<!-- sku管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" :title="dialogTitle" v-bind="dialog"
      @afterSubmitSuccess="afterSubmitSuccess" />
  </div>
</template>
<script>

import superTablePageFunction from '@/mixin/super-table-page-function';
export default {
  title: 'label_sku_categ_manage',
  mixins: [superTablePageFunction],
  data() {
    return {

      option: {
        search: {
          model: [
            { label: "label_categ_name", key: "name", type: 'input', },
          ],
        },

        action: [
          {
            label: this.$tt("label_add_level_categ", { level: 1 }), attrs: { icon: "el-icon-plus" }, click: () => {
              this.dialogTitle = this.$tt("label_add_level_categ", { level: 1 })
              this['$refs']['formDialog'].show({ igPid: 0, igStatus: "ENABLE" }, { setData: true })
            }
          },
        ],
        table: {
          autoPage: false,
          'row-key': "id",
          'tree-props': { children: 'children', hasChildren: 'hasChildren' },

          url: '/mms-api/client/MmsSkuCategoryInfoClientRpc/allCategory.json',
          urlDataHandle: (res) => {
            this.setLevel(res.data.rows, 1)
            return res.data.rows
          },
          model: [
            { key: 'name', label: 'label_categ_name', align: 'start' },
            {
              type: "operate", width: 200,
              operate: [
                {
                  label: (row) => this.$tt("label_add_level_categ", { level: row.level + 1 }), click: (row) => {
                    this.dialogTitle = this.$tt("label_add_level_categ", { level: row.level + 1 })
                    this['$refs']['formDialog'].show({ "igPid": row["id"], igStatus: "ENABLE", parentName: row.name }, { setData: true })
                  }
                },
                {
                  label: 'label_edit', click: (row) => {
                    this.dialogTitle = this.$tt("label_edit_level_categ", { level: row.level + 1 })
                    this['$refs']['formDialog'].show({ "id": row["id"] }, {
                      detailDataHandle: (data) => {
                        data.parentName = row.parentName
                        return data
                      }
                    })
                  }
                },

                {
                  label: 'label_delete', type: "confirm-button", url: '/mms-api/sku/MmsSkuCategoryInfoRpc/remove.json', message: '确定要删除该品类吗？',
                  buttonClass: "button_text_danger", confirmButtonType: 'danger',
                  params: (row) => { return { "id": row["id"] } }, done: ['tip', 'reload']
                },
              ],
            }
          ],
        }

        ,

      },

      dialogTitle: '',
      dialog: {
        submitUrl: '/mms-api/client/MmsSkuCategoryInfoClientRpc/saveUpdate.json',
        detailUrl: '/mms-api/client/MmsSkuCategoryInfoClientRpc/detail.json',
        form: {
          model: [
            { header: "label_base_info", },
            { key: 'parentName', label: 'label_super_categ', disabled: true, if: (r, c, v) => !!v },
            // { key: 'igLevel', label: '品类级别', disabled: true, },
            { key: 'igName', label: 'label_categ_name', },
            { key: 'igNameEn', label: 'label_categ_name_en', },
            // { key: 'igStatus', label: '是否启用', type: 'select', enum: 'IsAvailableStatusEnum',disabled: true, },
          ],
          rules: {
            // 'igPid': [{ required: true, message: '父ID', trigger: 'blur' }],
            'igName': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
            'igNameEn': [{ required: true, message: this.$tt('tip_can_no_empty'),  trigger: 'blur' }],
          },
        }
      },
    };
  },
  methods: {
    setLevel(list, level, item) {
      list.forEach(it => {
        it.level = level
        it.parentName = item ? item.name : ''
        if (it.children) this.setLevel(it.children, level + 1, it)
      })
    },

    afterSubmitSuccess(data) {
      this.reload()
    },
  }
};

</script>
<style></style>
